package org.jsets.fastboot.util;

import java.util.function.Consumer;

import cn.hutool.core.lang.Assert;

public class Asserts {
	
	public static void ifTrue(boolean expression, Executor executor) {
		if(expression) {
			executor.execute();
		}
	}
	
	/**
	 * 如果Empty，执行consumer
	 */
	public static void ifEmpty(final String string, Executor executor) {
		if (StringUtils.isEmpty(string)) {
			executor.execute();
		}
	}
	
	/**
	 * 如果非Empty，执行consumer
	 */
	public static void ifNotEmpty(final String string, Consumer<String> consumer) {
		if (!StringUtils.isEmpty(string)) {
			consumer.accept(string);
		}
	}
	
	/**
	 * 如果Blank，执行consumer
	 */
	public static void ifBlank(final String string, Executor executor) {
		if (StringUtils.isBlank(string)) {
			executor.execute();
		}
	}
	
	/**
	 * 如果非Blank，执行consumer
	 */
	public static void ifNotBlank(final String string, Consumer<String> consumer) {
		if (!StringUtils.isBlank(string)) {
			consumer.accept(string);
		}
	}
	
	public static void ifNull(Object object, Executor executor) {
		if(null==object) {
			executor.execute();
		}
	}
	
	public static <T> void ifNotNull(T object, Consumer<T> consumer) {
		if(null!=object) {
			consumer.accept(object);
		}
	}
	
	public static void main(String[] args) {
		Asserts.ifNotBlank("", t->
			System.out.println(1111)
		);
		Asserts.ifNotEmpty("", t->
			System.out.println(222)
		);
		Integer s = 0;
		Asserts.ifNotNull(s, t->s.toString());
	}
	
	
	
	
}
